'''
@Project ：my_python_project 
@File    ：test3_属性查找.py
@IDE     ：PyCharm 
@Author  ：xionglinhui
@Date    ：2024/10/15 上午9:04 
'''
class Student:
    '''打印学生信息'''
    # 1、变量的定义
    stu_school = 'old_boy'       # _Student__stu_school
                                 #           stu_school
    count = 0

    def __init__(self, x, y, z):
        Student.count += 1
        self.stu_name = x,
        self.stu_age = y,
        self.stu_gender = z
        # return 123  # 会报错 TypeError: __init__() should return None, not 'int'
        # return None   # 默认只能return None


    # 2、功能的定义
    def tell_stu_info(self):
        print('学生信息：名字：%s 年龄：%s 性别：%s' %(
            self.stu_name,
            self.stu_age,
            self.stu_gender
        ))
    def set_info(self,x,y,z):
        self.stu_name = x,
        self.stu_age = y,
        self.stu_gender = z

    def choose(self,x):
        print('正在选课')
        self.course=x

stu1_obj = Student('linhui',18,'male')
print(Student.__dict__)
stu2_obj = Student('dafeifei', 19, 'male')
stu3_obj = Student('xiong', 20, 'male')

# print(dir(stu1_obj)) # 查看对象的所有属性和方法，返回的是列表
# print(stu1_obj.__dict__) # 查看对象的

# 计算调用类的次数
# print(stu1_obj.count) # 输出 3  ， 类的属性和对象的属性是共用的，实例化时会调用类，对象获取到的count也就是类本身的count
# print(stu2_obj.count) # 输出 3
# print(stu3_obj.count) # 输出 3

# 类中存放的是对象共有的数据与功能
# 一：类可以访问：
# 1、类的数据属性
# print(Student.stu_school)
# print(stu1_obj.stu_school)
# 2、类的函数属性
# print(Student.tell_stu_info)
# print(Student.set_info)


# 二：但其实类中的东西是给对象用的
# 1、类的数据属性是共享给所有对象用的，大家访问的地址都一样

# print(id(Student.stu_school)) # 140406350253728
#
# print(id(stu1_obj.stu_school)) # 140406350253728
# print(id(stu2_obj.stu_school)) # 140406350253728
# print(id(stu3_obj.stu_school)) # 140406350253728
#
# Student.stu_school = 'DAFEIFEI'
# print(f'111--stu1_obj.stu_school: {stu1_obj.stu_school}')
# stu1_obj.stu_school = 'DAFEIFEI'
# print(f'222--stu1_obj.stu_school: {stu1_obj.stu_school}')

# 2、类中定义的函数主要是给对象使用的，而且是绑定给对象的，虽然所有对象指向的都是相同的功能，
#    但是绑定到不同的对象就是不同的绑定方法，内存地址各不相同

# # 类调用自己的函数属性必须严格按照函数的用法来
# print(Student.tell_stu_info)  # <function Student.tell_stu_info at 0x7f2ff3188d90>
# print(Student.set_info)       # <function Student.set_info at 0x7f2ff3188e18>

# Student.tell_stu_info(stu1_obj) # 学生信息：名字：('linhui',) 年龄：(18,) 性别：male
# Student.tell_stu_info(stu2_obj) # 学生信息：名字：('dafeifei',) 年龄：(19,) 性别：male
# Student.tell_stu_info(stu3_obj) # 学生信息：名字：('xiong',) 年龄：(20,) 性别：male
#
# Student.set_info(stu1_obj, 'wukong', 1000, 'male')
# Student.tell_stu_info(stu1_obj)  # 学生信息：名字：('wukong',) 年龄：(1000,) 性别：male


# 绑定方法的特殊之处在于：谁来调用绑定方法就会将谁当做第一个参数自动传入
# print(Student.tell_stu_info)  # <function Student.tell_stu_info at 0x7f198ef54e18>
# print(stu1_obj.tell_stu_info) # <bound method Student.tell_stu_info of <__main__.Student object at 0x7f198ef66c18>>
# print(stu2_obj.tell_stu_info) # <bound method Student.tell_stu_info of <__main__.Student object at 0x7f198ef66c50>>
# print(stu3_obj.tell_stu_info) # <bound method Student.tell_stu_info of <__main__.Student object at 0x7f198ef66c88>>
#
# stu1_obj.tell_stu_info() #tell_stu_info(stu1_obj) # 学生信息：名字：('linhui',) 年龄：(18,) 性别：male
# stu2_obj.tell_stu_info() #tell_stu_info(stu2_obj)
# stu3_obj.tell_stu_info() #tell_stu_info(stu3_obj)

# stu1_obj.choose('python全栈开发')
# print(stu1_obj.course)

# l1=['aa','bb','cc']
# print(l1.append)  # <built-in method append of list object at 0x7f7583313088>
#
# l1.append('dd')
# print(l1)    # ['aa', 'bb', 'cc', 'dd']
#
# list.append(l1, 'ee')
# print(l1)    # ['aa', 'bb', 'cc', 'dd', 'ee']
#
#
# list.ap